package org.jeecg.basic.controller;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.basic.entity.MesErrcodeCfg;
import org.jeecg.basic.entity.MesLinePartnoCfg;
import org.jeecg.basic.service.IMesErrcodeCfgService;
import org.jeecg.basic.service.IMesLinePartnoCfgService;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
* @Description: 错误代码配置
* @Author: Liting
* @Date:   2024-09-23
* @Version: V1.0
*/
@Api(tags="错误代码配置")
@RestController
@RequestMapping("/basic/mesErrcodeCfg")
@Slf4j
public class MesErrcodeCfgController extends JeecgController<MesErrcodeCfg, IMesErrcodeCfgService> {
   @Autowired
   private IMesErrcodeCfgService mesErrcodeCfgService;

   /**
    * 分页列表查询666
    *
    * @param mesErrcodeCfg
    * @param pageNo
    * @param pageSize
    * @param req
    * @return
    */
   //@AutoLog(value = "错误代码配置-分页列表查询")
   @ApiOperation(value="错误代码配置-分页列表查询", notes="错误代码配置-分页列表查询")
   @GetMapping(value = "/list")
   @DS("#header.his")
   public Result<IPage<MesErrcodeCfg>> queryPageList(MesErrcodeCfg mesErrcodeCfg,
                                  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                  HttpServletRequest req) {
       QueryWrapper<MesErrcodeCfg> queryWrapper = QueryGenerator.initQueryWrapper(mesErrcodeCfg, req.getParameterMap());
//       queryWrapper.in("partno",partNo,pnGroup);
       Page<MesErrcodeCfg> page = new Page<MesErrcodeCfg>(pageNo, pageSize);
       IPage<MesErrcodeCfg> pageList = mesErrcodeCfgService.page(page, queryWrapper);
       return Result.OK(pageList);
   }

   /**
    *   添加
    *
    * @param mesErrcodeCfg
    * @return
    */
   @AutoLog(value = "错误代码配置-添加")
   @ApiOperation(value="错误代码配置-添加", notes="错误代码配置-添加")
   //@RequiresPermissions("org.jeecg.modules.demo:mes_line_partno_cfg:add")
   @PostMapping(value = "/add")
   @DS("#header.line")
   public Result<String> add(@RequestBody MesErrcodeCfg mesErrcodeCfg) {
       mesErrcodeCfgService.save(mesErrcodeCfg);
       return Result.OK("添加成功！");
   }

   /**
    *  编辑
    *
    * @param mesErrcodeCfg
    * @return
    */
   @AutoLog(value = "错误代码配置-编辑")
   @ApiOperation(value="错误代码配置-编辑", notes="错误代码配置-编辑")
   //@RequiresPermissions("org.jeecg.modules.demo:mes_line_partno_cfg:edit")
   @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
   @DS("#header.line")
   public Result<String> edit(@RequestBody MesErrcodeCfg mesErrcodeCfg) {
       mesErrcodeCfgService.updateByMultiId(mesErrcodeCfg);
       return Result.OK("编辑成功!");
   }

   /**
    *   通过选中对象删除
    *
    * @param mesErrcodeCfg
    * @return
    */
   @AutoLog(value = "错误代码配置-通过id删除")
   @ApiOperation(value="错误代码配置-通过id删除", notes="错误代码配置-通过id删除")
   //@RequiresPermissions("org.jeecg.modules.demo:mes_line_partno_cfg:delete")
   @RequestMapping(value = "/delete")
   public Result<String> delete(@RequestBody MesErrcodeCfg mesErrcodeCfg) {
       mesErrcodeCfgService.deleteByMultiId(mesErrcodeCfg);
       return Result.OK("删除成功!");
   }

   /**
    *  批量删除
    *
    * @param list
    * @return
    */
   @AutoLog(value = "错误代码配置-批量删除")
   @ApiOperation(value="错误代码配置-批量删除", notes="错误代码配置-批量删除")
   //@RequiresPermissions("org.jeecg.modules.demo:mes_line_partno_cfg:deleteBatch")
   @RequestMapping(value = "/deleteBatch")
   public Result<String> deleteBatch(@RequestBody List<MesErrcodeCfg> list) {
       list.forEach(item->{
           mesErrcodeCfgService.deleteByMultiId(item);
           });
       return Result.OK("批量删除成功!");
   }

   /**
    * 通过id查询
    *
    * @param id
    * @return
    */
   //@AutoLog(value = "产线产品路由配置-通过id查询")
   @ApiOperation(value="错误代码配置-通过id查询", notes="错误代码配置-通过id查询")
   @GetMapping(value = "/queryById")
   @DS("#header.his")
   public Result<MesErrcodeCfg> queryById(@RequestParam(name="id",required=true) String id) {
       MesErrcodeCfg mesErrcodeCfg = mesErrcodeCfgService.getById(id);
       if(mesErrcodeCfg==null) {
           return Result.error("未找到对应数据");
       }
       return Result.OK(mesErrcodeCfg);
   }

   /**
   * 导出excel
   *
   * @param request
   * @param mesErrcodeCfg
   */
   //@RequiresPermissions("org.jeecg.modules.demo:mes_line_partno_cfg:exportXls")
   @RequestMapping(value = "/exportXls")
   @DS("#header.his")
   public ModelAndView exportXls(HttpServletRequest request, MesErrcodeCfg mesErrcodeCfg) {
       return super.exportXls(request, mesErrcodeCfg, MesErrcodeCfg.class, "错误代码配置");
   }

   /**
     * 通过excel导入数据
   *
   * @param request
   * @param response
   * @return
   */
   //@RequiresPermissions("mes_line_partno_cfg:importExcel")
   @DS("#header.line")
   @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
   public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
       return super.importExcel(request, response, MesErrcodeCfg.class);
   }

}
